﻿using System;
using System.Xml.Serialization;

namespace DC2010.Objects
{
    public class DungeonLoc : ICloneable
    {
		[XmlAttribute]
        public string FloorId { get; set;}
        
		[XmlAttribute]
		public int X { get; set;}
        
		[XmlAttribute]
		public int Y { get; set;}
        
		[XmlAttribute]
		public Directions Facing { get; set;}

        public DungeonLoc()
        { 
        }

        public DungeonLoc(string floorId, int x, int y, Directions facing)
        {
            FloorId = floorId;
            X = x;
            Y = y;
            Facing = facing;
        }

        #region ICloneable Members

        public object Clone()
        {
            return MemberwiseClone();
        }

        #endregion

        /// <summary>
        /// Changes current party direction - facing
        /// </summary>
        public void TurnRight()
        {
            int i = (int) Facing;
            i++;

            // if too much, set to north again
            if (i >= 4) i = 0;

            Facing = (Directions)i;
        }

        /// <summary>
        /// Changes current party direction - facing
        /// </summary>
        public void TurnLeft()
        {
            int i = (int)Facing;
            i--;

            // if too much, set to west again
            if (i < 0) i = 3;

            Facing = (Directions)i;
        }
		
        /// <summary>
        /// Changes current party direction - 180
        /// </summary>		
		public void TurnOposite()
		{
            int i = ((int)Facing+2)&3;
            Facing = (Directions)i;
		}
		
		/// <summary>
		/// Oposite direction to Facing...
		/// </summary>		
        public Directions Oposite
		{
			get
			{
                Directions dir;
				int i = ((int)Facing+2)&3;
				dir = (Directions)i;	
				
				return dir;
			}
		}
    }
}
